<?

$tmppath="../../";
REQUIRE ($tmppath."include/login.php");
REQUIRE ($tmppath."$templates/up.php");
REQUIRE($tmppath."protect/connect.php");
REQUIRE("permition.php");
REQUIRE("ville_function.php");

$query="SELECT  ville_name, ville_population,  ville_Tcriminalite ,ville_t_occupe,ville_niv from sdville  where ville_id=$ville";
// 0= nom  1 = population total  2= taux criminalite 3= tribut occupee 
$resultat=mysql_query($query);
$tmp=mysql_fetch_row($resultat);
$ville_niv=$tmp[4];




$criminalite=$tmp[2];
IF ($criminalite!=0){
$tribu_inexe=floor(($tmp[1]*($criminalite/100))/100);
}
else{
$tribu_inexe=0;
}


$population_libre=$tmp[1];
$tribu_total=floor($population_libre/100);
$tribu_libre=$tribu_total-$tmp[3]-$tribu_inexe;


//***************************
//Selection des construction
//***************************

$query="SELECT construction_id, construction_tribu, construction_total,construction_tavancement,construction_avancement, construction_batiment FROM tmpconstruction WHERE construction_id=$construction";
// 0 = id, 1 = tribu 2=tempstotal 3 =taux d'avancement 4=avancement 5=batiment construit.
$resultat=mysql_query($query);
$batiment=mysql_fetch_row($resultat);
$btribu=$batiment[1]; //Tribu de batiment.
$btotal=$batiment[2]; //Temps de construction total.
$btaux=$batiment[3]; //
$bdejac=$batiment[4];;//Deja construit.

$tour=ceil(($btotal-$bdejac)/($btaux*$btribu)); // tour a attendre

//***************************
//Selection du batiment.
//***************************
$query="SELECT batiment_icon, batiment_name FROM ubatiment WHERE batiment_id=$batiment[5]";
// 0 = image, 1 = nom.
$resultat=mysql_query($query);
$batiment=mysql_fetch_row($resultat);
mysql_close;
$bimage=$batiment[0];
$bname=$batiment[1];




REQUIRE("../fonction.php");
$titre="Modifier construction.";
TITRE_JEU($titre);
?>

<title>Sombre destin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
@import url(../../templates/default/vrt-team.css);
</style>
</head>
<body bgcolor="#00CCFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!***********************************************************************
***********Les script javascript de la page***************************
***********************************************************************>

<script language="JavaScript" type="text/JavaScript">
<!--

tribulibre=<? echo $tribu_libre+$btribu ?>;

tmpsconstr=<? echo $btotal ?>;
tauxc=<? echo $btaux ?>;
dejac=<? echo $bdejac ?>;
tribu_max=<? echo $ville_niv*10 ?>;

function add(){
var tribul=document.form1.tribul.value;
var tribu=document.form1.tribu.value;
		
	if (tribul!=0 && tribu<tribu_max){
		document.form1.tribu.value++;
		document.form1.tribul.value--;
	}

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}


 
	
}

function sous(){
var tribul=document.form1.tribul.value;
var tribu=document.form1.tribu.value;
		
		if (document.form1.tribu.value!=0){
			document.form1.tribu.value--;
			document.form1.tribul.value++;
		}	

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}

}
function onch(){
		document.form1.tribul.value= tribulibre-document.form1.tribu.value;
		if (document.form1.tribu.value<0){ document.form1.tribu.value=0; document.form1.tribul.value=tribulibre; }
		if (document.form1.tribu.value>tribulibre){ document.form1.tribu.value=tribulibre;document.form1.tribul.value=0; }
		if (document.form1.tribu.value>tribu_max){ document.form1.tribu.value=tribu_max; document.form1.tribul.value=tribulibre-tribu_max; }
			
	
	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}
}


function onch2(){
		document.form1.tribul.value= tribulibre-document.form1.tribu.value;		
	    if (document.form1.tribu.value!=0){
			chgtour() 
		}
}

function chgtour(){
 document.form2.tourc.value=Math.ceil((<? echo "$btotal-$bdejac"; ?>)/(<? echo "$btaux*document.form1.tribu.value";?>));
}

//-->
</script>
<!/***********************************************************************
******************************Fin des javascripts***********************
***********************************************************************>
<div align="center">
<?
if (!empty($erreur)){
echo"<table width=\"85%\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" background=\"../Templates/Default/Fond.jpg\"><tr><td><strong><font color=\"#FF0000\">$erreur</font></strong></td></table><BR>";

}


?>
  <table width="75%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><p align="center">&nbsp;</p>
        <form method="post" name="form1" action="ville_test.php" target="_self">
          <div align="center"></div>
          <table width="300" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#333333">
            <tr> 
              <td width="141"><div align="right">Tribut libre :</div></td>
              <td width="153"> 
                <input name="tribul" type="text" id="tribul" value="<? echo $tribu_libre ?>" size="10" maxlength="5" onChange="onch2()" READONLY></td>
            </tr>
          </table>
          <p align="center">&nbsp;</p>
          <p align="center"><strong>Construction :</strong></p>
          <table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="40%"><div align="center"><img src="<? echo"../../images/batiments/$bimage";?>" name="imgbatiment" width="50" height="50" border="1" align="middle" id="imgbatiment"></div></td>
              <td width="60%"><div align="center"><? echo $bname;?> </div></td>
            </tr>
          </table>
          <br>
          <table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td><div align="right">Combien de Tribu? : </div></td>
              <td><div align="center">
                  <input type="button" name="Submit22" value="-" onClick="sous()">
                  <input name="tribu" type="text" id="tribu" value="<? echo $btribu;?>" size="5" maxlength="3" onChange="onch()">
                  <input type="button" name="Submit2" value="+" onClick="add()">
                </div></td>
            </tr>
          </table>
          <p align="center"> 
            <?
	echo"<input name=\"construction\" type=\"hidden\" id=\"construction\" value=\"$construction\">";

 
	
	echo"<input name=\"ville\" type=\"hidden\" id=\"ville\" value=\"$ville\">";
	echo"<input name=\"tribu_libre\" type=\"hidden\" id=\"tribu_libre\" value=\"$tribu_libre\">";

 
	?>
            <input name="choix" type="hidden" id="choix" value="mod-construire">
            <input type="submit" name="Submit" value="Envoyer" >
          </p>
          </form>
        <form name="form2" method="post" action="">
          <p>&nbsp;</p>
          <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
            <tr> 
              <td width="52%"><div align="center">Temps de construction :<br>
                  <input name="tmpc" type="text" id="tmpc6" value="<? echo $btotal ?>" size="10" maxlength="10" READONLY>
                  <br>
                  Deja construit :<br>
                  <input name="tmpc2" type="text" id="tmpc22" value="<? echo $bdejac ?>" size="10" maxlength="10" READONLY>
                  <br>
                  Tour pour la construction :<br>
                  <input name="tourc" type="text" id="tourc3" value="<? echo "$tour"; ?>" size="10" maxlength="10" READONLY>
                </div></td>
              <td width="48%" height="0"> <div align="center"><br>
                </div></td>
            </tr>
          </table>
        </form>
        
      </td>
    </tr>
  </table>
  <p align="left">&nbsp;</p>
</div>
</body></html>
